#include "frame.h"
#include <QApplication>
#include <QMouseEvent>

namespace yc {

Frame::Frame(QWidget* parent) : QFrame(parent) { }

void Frame::mousePressEvent(QMouseEvent* e)
{
    QFrame::mousePressEvent(e);
    if (e->button() == Qt::LeftButton) {
        press_pos_ = e->pos();
        e->accept();
    }
}

void Frame::mouseReleaseEvent(QMouseEvent* e)
{
    QFrame::mouseReleaseEvent(e);
    if (e->button() == Qt::LeftButton) {
        const QPoint offset = e->pos() - press_pos_;
        if (offset.manhattanLength() < QApplication::startDragDistance()) {
            Q_EMIT clicked();
            e->accept();
        }
    }
}

} // namespace yc
